home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / pldtik.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  2KB  |  71 lines

  1. /* If tick == 0, this works out a "nice" interval, so that there */
  2. /* are between 3 and 7.5 major tick intervals in the input range */
  3. /* "vmin" to "vmax". Using this value for the tick interval or   */
  4. /* supplied value, it also computes "prec" which specifies       */
  5. /* the number of places that should be written after the decimal */
  6. /* point. The recommended number of subticks is returned in      */
  7. /* "nsubt" unless the routine is entered with a non-zero value   */
  8. /* of "nsubt". The output variable "mode" is set to 0 if         */
  9. /* labels are to be written in floating-point format, or to 1 if */
  10. /* they are to be written in fixed-point format.                 */
  11.                                                                 
  12. #include "plplot.h"
  13. #include <math.h>
  14.  
  15. void pldtik(vmin, vmax, tick, nsubt, mode, prec)
  16. float vmin, vmax, *tick;
  17. int *nsubt, *mode, *prec;
  18. {
  19.       
  20.       float t1, t2, vmod;
  21.       int msd, np, ns;
  22.  
  23.       vmod = max(fabs(vmin),fabs(vmax));
  24.       *mode = 0;
  25.       if (vmod < 1.0e-2 || vmod > 1.0e6) *mode = 1;
  26.       t1 = (float)log10(vmod);
  27.       msd = (int)t1;
  28.  
  29.       t1 = (float)log10(fabs(vmax-vmin));
  30.       np = (int)t1;
  31.       t1 = t1 - np;
  32.       
  33.       if (t1 > 0.7781512503) {
  34.         t2 = 2.0 ;
  35.         ns = 4;
  36.       }
  37.       else if (t1 > 0.4771212549) {
  38.         t2 = 1.0 ;
  39.         ns = 5;
  40.       }
  41.       else if (t1 > 0.1760912591) {
  42.         t2 = 5.0;
  43.         ns = 5;
  44.         np = np-1;
  45.       }
  46.       else  {
  47.         t2 = 2.0;
  48.         ns = 4;
  49.         np = np-1;
  50.       }
  51.  
  52.       if (*tick == 0.0) {
  53.         *tick = t2 * pow(10.0,(double)np);
  54.         if (vmin > vmax) *tick = -*tick;
  55.         if (*nsubt == 0) *nsubt = ns;
  56.         if (*mode != 0) 
  57.           *prec = msd - np;
  58.         else
  59.           *prec = max(-np,0);
  60.       }
  61.       else  {
  62.         t1 = (float)log10(fabs(*tick));
  63.         np = (int)t1;
  64.         if (*mode != 0) 
  65.           *prec = msd - np + 1;
  66.         else
  67.           *prec = max(-np+1,0);
  68.       }
  69. }
  70.  
  71.